#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e5 + 10;

struct Record {
    string name;
    int age, worth;
}record[N];

bool cmp(const Record & r1, const Record & r2) {
    if (r1.worth == r2.worth) {
        if (r1.age == r2.age)
            return r1.name < r2.name;
        return r1.age < r2.age;
    } 
    return r1.worth > r2.worth;
}

int n, m;

inline void solution() {
    cin >> n >> m;
    char name[10];
    t1 = clock();
    for (int i = 0; i < n; i ++ ) {
        scanf("%s%d%d", name, &record[i].age, &record[i].worth);
        record[i].name = name;
    }
    sort(record, record + n, cmp);
    for (int i = 1; i <= m; i ++ ) {
        int k, l, r;
        scanf("%d%d%d", &k, &l, &r);
        int cnt = 0;
        printf("Case # %d:\n", i);
        for (int j = 0; j < n; j ++ ) {
            if (record[j].age >= l && record[j].age <= r) {
                printf("%s %d %d\n", record[j].name.c_str(), record[j].age, record[j].worth);
                cnt ++ ;
            }
            if (cnt == k) break;
        }
        if (cnt == 0) printf("None\n");
       
    }
    t2 = clock();
    printf("%.3f s\n",(double)(t2 - t1)/ CLOCKS_PER_SEC);
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}